1041A - Heist - CodeForces Solution


greedy implementation sortings *800

Please click on ads to support us..

Python Code:

n=int(input())
l = list(map(int, input().split()))
a=max(l)-min(l)+1
print(a-n)
		 			     				  	  			  		  		

C++ Code:

//This is coded by NISHANTH VM
//#include <bits/stdc++.h>
#include <iostream> 
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> mii;
typedef map<int,v32> miv;
ll MOD = 998244353;
double eps = 1e-12;
#define rep(i,e) for(ll i = 0; i < e; i++)
#define repFR(i,s,e) for(ll i = s; i < e; i++)
#define repR(i,s) for(ll i = s; i >= 0; i--)
#define repRR(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
 

void solve(){
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n,a;
cin>>n;
cin>>a;
int low = a;
int high = a;
for(int i=1;i<n;i++){
    cin>>a;
    if(a<low){
        low = a;
    }
    if(a>high){
        high = a;
    }
}
cout<<(high-low+1)-n<<"\n";
}
int main()
{
fast_cin();
 solve();
 return 0;
}


Comments

Submit
0 Comments
More Questions

1536C - Diluc and Kaeya
1428C - ABBB
1557A - Ezzat and Two Subsequences
255A - Greg's Workout
1059A - Cashier
1389C - Good String
1561A - Simply Strange Sort
1337B - Kana and Dragon Quest game
137C - History
1443C - The Delivery Dilemma
6C - Alice Bob and Chocolate
1077C - Good Array
285B - Find Marble
6A - Triangle
1729A - Two Elevators
1729B - Decode String
1729C - Jumping on Tiles
1729E - Guess the Cycle Size
553B - Kyoya and Permutation
1729D - Friends and the Restaurant
1606C - Banknotes
580C - Kefa and Park
342A - Xenia and Divisors
1033A - King Escape
39D - Cubical Planet
1453A - Cancel the Trains
645A - Amity Assessment
1144A - Diverse Strings
1553B - Reverse String
1073A - Diverse Substring